﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Reader.Core.Application
{
    public class Result
    {
        /// <summary>
        /// 成功/失败
        /// </summary>
        public bool Success { get; set; }
        /// <summary>
        /// 错误消息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 状态码
        /// </summary>
        public int Code { get; set; }
    }
    public class Result<T> : Result
    {
        /// <summary>
        /// 返回的数据
        /// </summary>
        public T Data { get; set; }
    }
    public class ResultStatus
    {
        public static Result Success()
        {
            return Success(null);
        }
        public static Result Success(string message = null)
        {
            return new Result() { Success = true, Code = 0, Message = message };
        }
        public static Result Fail()
        {
            return Fail(null);
        }
        public static Result Fail(string message = null)
        {
            return Fail(-1, message);
        }
        public static Result Fail(int code = -1, string message = null)
        {
            return new Result { Success = false, Code = code, Message = message };
        }
    }
    public class ResultStatus<T> : ResultStatus
    {
        public static Result<T> Success(T data)
        {
            return Success(data, null);
        }
        public static Result<T> Success(T data, string message = null)
        {
            return new Result<T> { Success = true, Code = 0, Message = message, Data = data };
        }
        public static Result<T> Fail(T data)
        {
            return Fail(data, null);
        }
        public static Result<T> Fail(T data, string message = null)
        {
            return Fail(data, -1, message);
        }
        public static Result<T> Fail(T data, int code = -1, string message = null)
        {
            return new Result<T> { Success = false, Code = code, Message = message, Data = data };
        }
    }
}
